package com.nameless.controller.api;

import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nameless.entity.Logininfor;
import com.nameless.service.LoginInfoService;
import com.nameless.vo.LoginLogVo;
import com.nameless.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : 陈灰灰
 * @Date: 2023/03/01/14:26
 * @Description:
 */
@Api(value = "/system/api/log", tags = {"登录日志控制层"})
@RestController
@RequestMapping("/system/api/log")
public class ApiLoginInfoController {
    @Autowired
    private LoginInfoService loginInfoService;

    /**
     * @Author
     * 查询所有日志
     * @param loginLogVo 登录日志签证官
     * @return {@link Result}
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "LoginLogVo", name = "loginLogVo", value = "登录日志签证官", required = true)
    })
    @ApiOperation(value = "查询所有日志", notes = "查询所有日志")
    @RequestMapping("/query")
    public Result queryAllLogs(LoginLogVo loginLogVo){
        Page<Logininfor> page = new Page<>(loginLogVo.getPageNo(), loginLogVo.getPageSize());
        LambdaQueryWrapper<Logininfor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByAsc(Logininfor::getInfoId);
        queryWrapper.like(StringUtils.isNotEmpty(loginLogVo.getUserName()),Logininfor::getUserName,loginLogVo.getUserName());
        Page<Logininfor> page1 = loginInfoService.page(page, queryWrapper);
        return new Result(200,"查询成功",page1);
    }

    /**
     * @Author chh
     * 根据id删除日志
     * @param infoid infoid
     * @return {@link Result}
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "infoid", value = "infoid", required = true)
    })
    @ApiOperation(value = "根据id删除日志", notes = "根据id删除日志")
    @RequestMapping("delete")
    public Result delete(Integer infoid){
        loginInfoService.removeById(infoid);
        return new Result(200,"删除成功");
    }


}
